using System.Web.Mvc;
using Dyn.News.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Routable.Services;
using Orchard.Mvc.Extensions;

namespace Dyn.News.Extensions {
    public static class UrlHelperExtensions {
        public static string Category(this UrlHelper urlHelper) {
            return urlHelper.Action("List", "Category", new { area = "Dyn.News" });
        }

        public static string CategoryForAdmin(this UrlHelper urlHelper)
        {
            return urlHelper.Action("List", "CategoryAdmin", new {area = "Dyn.News"});
        }

        public static string Category(this UrlHelper urlHelper, NewsCategoryPart categoryPart)
        {
            return urlHelper.Action("Item", "Category", new { categoryPath = categoryPart.As<IRoutableAspect>().Path, area = "Dyn.News" });
        }

        public static string CategoryLiveWriterManifest(this UrlHelper urlHelper, NewsCategoryPart CategoryPart)
        {
            return urlHelper.AbsoluteAction(() => urlHelper.Action("Manifest", "LiveWriter", new { area = "XmlRpc" }));
        }

        public static string CategoryRsd(this UrlHelper urlHelper, NewsCategoryPart CategoryPart)
        {
            return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "RemoteCategoryPublishing", new { categoryPath = CategoryPart.As<IRoutableAspect>().Path, area = "Dyn.News" }));
        }

        public static string CategoryArchiveYear(this UrlHelper urlHelper, NewsCategoryPart categoryPart, int year)
        {
            return urlHelper.Action("ListByArchive", "Article", new { categoryPath = categoryPart.As<IRoutableAspect>().Path, archiveData = year.ToString(), area = "Dyn.News" });
        }

        public static string CategoryArchiveMonth(this UrlHelper urlHelper, NewsCategoryPart categoryPart, int year, int month)
        {
            return urlHelper.Action("ListByArchive", "Article", new { categoryPath = categoryPart.As<IRoutableAspect>().Path, archiveData = string.Format("{0}/{1}", year, month), area = "Dyn.News" });
        }

        public static string CategoryArchiveDay(this UrlHelper urlHelper, NewsCategoryPart categoryPart, int year, int month, int day)
        {
            return urlHelper.Action("ListByArchive", "Article", new { categoryPath = categoryPart.As<IRoutableAspect>().Path, archiveData = string.Format("{0}/{1}/{2}", year, month, day), area = "Dyn.News" });
        }

        public static string CategoryForAdmin(this UrlHelper urlHelper, NewsCategoryPart categoryPart) {
            return urlHelper.Action("Item", "CategoryAdmin", new { categoryId = categoryPart.Id, area = "Dyn.News" });
        }

        public static string CategoryCreate(this UrlHelper urlHelper) {
            return urlHelper.Action("Create", "CategoryAdmin", new { area = "Dyn.News" });
        }

        public static string CategoryEdit(this UrlHelper urlHelper, NewsCategoryPart CategoryPart) {
            return urlHelper.Action("Edit", "CategoryAdmin", new { categoryID = CategoryPart.Id, area = "Dyn.News" });
        }

        public static string CategoryRemove(this UrlHelper urlHelper, NewsCategoryPart CategoryPart) {
            return urlHelper.Action("Remove", "CategoryAdmin", new { categoryID = CategoryPart.Id, area = "Dyn.News" });
        }

        public static string ArticleCreate(this UrlHelper urlHelper, NewsCategoryPart CategoryPart) {
            return urlHelper.Action("Create", "ArticleAdmin", new { categoryID = CategoryPart.Id, area = "Dyn.News" });
        }

        public static string Article(this UrlHelper urlHelper, ArticlePart ArticlePart) {
            return urlHelper.Action("Item", "Article", new { categoryPath = ArticlePart.CategoryPart.As<IRoutableAspect>().Path, postSlug = ArticlePart.As<IRoutableAspect>().GetEffectiveSlug(), area = "Dyn.News" });
        }

        public static string ArticleEdit(this UrlHelper urlHelper, ArticlePart ArticlePart) {
            return urlHelper.Action("Edit", "ArticleAdmin", new { categoryID = ArticlePart.CategoryPart.Id, articleId = ArticlePart.Id, area = "Dyn.News" });
        }

        public static string ArticleDelete(this UrlHelper urlHelper, ArticlePart ArticlePart) {
            return urlHelper.Action("Delete", "ArticleAdmin", new { categoryID = ArticlePart.CategoryPart.Id, articleId = ArticlePart.Id, area = "Dyn.News" });
        }

        public static string ArticlePublish(this UrlHelper urlHelper, ArticlePart ArticlePart) {
            return urlHelper.Action("Publish", "ArticleAdmin", new { categoryID = ArticlePart.CategoryPart.Id, articleId = ArticlePart.Id, area = "Dyn.News" });
        }

        public static string ArticleUnpublish(this UrlHelper urlHelper, ArticlePart ArticlePart) {
            return urlHelper.Action("Unpublish", "ArticleAdmin", new { categoryID = ArticlePart.CategoryPart.Id, articleId = ArticlePart.Id, area = "Dyn.News" });
        }
    }
}